﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Touch2Like.DAL;
using System.Data;
using System.Collections;
using OpenFlashChart;

namespace Touch2Like.Web.Customer
{
    public partial class Dashboard : System.Web.UI.Page
    {
        OpenFlashChart.OpenFlashChart chart = new OpenFlashChart.OpenFlashChart();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (WebUtility.UserGUID == "0")
            {
                Response.Redirect("/Customer/signin.aspx?next=" + Server.UrlEncode("/Customer/Dashboard.aspx"));
            }

            this.Master.CurrentPage = "NFCTagManager";

            if (!IsPostBack)
            {
                //runStatistics();
            }
        }



        //void runStatistics()
        //{
        //    ActivityDAL tag = new ActivityDAL();
        //    DateTime startDate = Convert.ToDateTime(tb_StartDate.Text), endDate = Convert.ToDateTime(tb_EndDate.Text).AddDays(1);
        //    DataTable dt = tag.GetDateStatistics(0, "", startDate, endDate);
        //    //DataTable dt = tag.GetDayStatistics(0, Request["TagUID"], Convert.ToDateTime("12/10/2010 00:00:00"), Convert.ToDateTime("12/10/2013 00:00:00"));
        //    ArrayList data1 = new ArrayList();
        //    List<string> label1 = new List<string>();
        //    double max = 0;
        //    for (int i1 = 0; startDate < endDate; startDate = startDate.AddDays(1))
        //    {
        //        if (i1 % 5 == 0)
        //            label1.Add(FormatDate(startDate));
        //        else
        //            label1.Add("");

        //        double val = 0;
        //        if (dt.Select("TouchDay='" + FormatDate(startDate) + "'").Length > 0)
        //        {
        //            val = Convert.ToDouble(dt.Select("TouchDay='" + FormatDate(startDate) + "'")[0]["TouchCount"]);
        //            BarFilledValue v = new BarFilledValue(val, 0);
        //            v.Tip = FormatDate(startDate);
        //            data1.Add(v);
        //            if (val > max) max = val;
        //        }
        //        else
        //        {
        //            data1.Add(0);
        //        }
        //        i1 = i1 + 1;
        //    }

        //    OpenFlashChart.Bar bar1 = new Bar();
        //    bar1.Values = data1;

        //    bar1.Tooltip = "Tooltip:#val#";

        //    chart.X_Axis.Labels.SetLabels(label1);

        //    chart.Bgcolor = "#ffffff";
        //    chart.X_Axis.GridColour = chart.Bgcolor;
        //    chart.Y_Axis.GridColour = chart.Bgcolor;

        //    chart.AddElement(bar1);

        //    chart.Title = new Title("Total Touchs");
        //    int temp1 = Convert.ToInt32(max / 7) + 1;
        //    chart.Y_Axis.SetRange(0, temp1 * 7, temp1);
        //    chart.Tooltip = new ToolTip("Global tooltip:#val#");
        //    chart.Tooltip.Shadow = true;
        //    chart.Tooltip.Colour = "#e43456";
        //    chart.Tooltip.MouseStyle = ToolTipStyle.CLOSEST;
        //    OpenFlashChartControl1.EnableCache = false;
        //    OpenFlashChartControl1.Chart = chart;
        //}

        string FormatDate(DateTime d)
        {
            string year = d.Year.ToString(), month = d.Month.ToString(), day = d.Day.ToString();
            if (d.Month.ToString().Length < 2) month = "0" + d.Month;
            if (d.Day.ToString().Length < 2) day = "0" + d.Day;
            return year + "-" + month + "-" + day;
        }
    }
}